package free.order.tag;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

public class PathTag extends TagSupport {

	private static final long serialVersionUID = 8627044965380095335L;
	
	private String file;

	public PathTag(){
		super();
	}
	
	public int doStartTag() throws JspTagException{
		return  SKIP_BODY;
	}

	public int doEndTag() throws JspTagException{
		
		HttpServletRequest request = (HttpServletRequest)super.pageContext.getRequest();
		StringBuilder strBuilder = new StringBuilder();
		strBuilder.append("<script language='javascript' src='");
		strBuilder.append(request.getContextPath()).append("/");
		strBuilder.append("scripts/").append(file);
		strBuilder.append("'></script>");
		try {
			super.pageContext.getOut().write(strBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}
}
